package com.mlong.admin.modular.unicomjs.formatter;

import com.kordar.admin.kernel.util.SpringUtil;
import com.kordar.datalist.formatter.Formatter;
import com.mlong.admin.modular.unicomjs.entity.GoodsType;
import com.mlong.admin.modular.unicomjs.service.GoodsTypeService;

import java.util.Map;
import java.util.stream.Collectors;

public class GoodsTypeFormatter implements Formatter<String> {

    private Map<Long, String> map;

    @Override
    public String format(Object value, Object... params) {
        if (map == null) {
            GoodsTypeService service = SpringUtil.getBean(GoodsTypeService.class);
            map = service.list().stream().collect(Collectors.toMap(GoodsType::getId, GoodsType::getName));
        }
        return map.get((Long) value);
    }
}
